package com.zs.toolbox.web2j.common.web;

import org.apache.commons.lang3.reflect.FieldUtils;

/**
 * @author shuai.zhang  on 2018/9/27
 * @description
 */
public class WtCommonPropertiesSetter {
    public static void setDefaultCommonProperty(Object dest) {
        setDefaultCommonProperty(dest, 0L);
    }

    public static void setDefaultCommonProperty(Object dest, Long userId) {

        try {
            if (FieldUtils.readDeclaredField(dest, "id", true) == null) {
                try {
                    if (userId == null) {
                        userId = 0L;
                    }
                    FieldUtils.writeDeclaredField(dest, "createUser", userId, true);
                } catch (Exception e) {
                }

//                try {
//                    FieldUtils.writeDeclaredField(dest, "createTime", LocalDateTime.now(), true);
//                } catch (Exception e) {
//                }

                try {
                    FieldUtils.writeDeclaredField(dest, "deleteStatus", 1, true);
                } catch (Exception e) {
                }
            }
        } catch (Exception e) {
        }

//        try {
//            FieldUtils.writeDeclaredField(dest, "updateTime", LocalDateTime.now(), true);
//        } catch (Exception e) {
//        }


    }
}
